<?php
/*
Copyright FLV Hosting
*/

	require_once '../config.php' ;
    //echo $_SERVER['PHP_AUTH_USER'];
	 //if(!isset($_SERVER['PHP_AUTH_USER']) || ($_SERVER['PHP_AUTH_USER']!=_ADMIN_LOGIN || $_SERVER['PHP_AUTH_PW'] != _ADMIN_PASSWORD)) {
	   //header('WWW-Authenticate: Basic realm="Administration"');
	   //header('HTTP/1.0 401 Unauthorized');
	   //echo '<p><center><b>This site requires a valid login and password.</b></center>';
	   //exit;
	 //}

	 $is_logged = Session::isLogin();
	 if  (!$is_logged) {
		header('Location: '. 'http://'._HOST.'/login.htm');
		return;
	 }

     $user_id = Session::getUserId();
     $is_admin = User::isUserAdmin($user_id);
     $is_author = User::isUserArticleWriter($user_id);
     if  (!$is_admin && !$is_author) {
		header('Location: '. 'http://'._HOST.'/myprofile/index.htm');
		return;
	 }


	require_once _LIB.'/abstract.php' ;
	require_once _LIB.'/mysql.php' ;
	require_once _LIB.'/paginate.php' ;
	require_once _LIB.'/main.php' ;

	# workout
	if($_REQUEST[actiontype]=='update') {
		mov_update($_REQUEST[ef], $_REQUEST[m_name], $_REQUEST[m_thumb], $_REQUEST[m_var], $_REQUEST[m_txt], $_REQUEST[replace_date]);
		//debug(0);
	} // i f
	if($_REQUEST[actiontype]=='cleardb') {
		movlist_clear();
		//debug(0);
	} // i f
	if($_REQUEST[actiontype]=='getxml') {
		movlist_sendxml(movlist_xml());
		//debug(0);
	} // i f
	if($_REQUEST[d]) {
		mov_del($_REQUEST[d]);
		//debug(0);
	} // i f


	$allfiles = get_dir(_APP.'/movies', 4);
	sort($allfiles, SORT_STRING);
	$pm = paginate(count($allfiles) ,'p',array('itemsperpage'=>10, 'items'=>10)) ;
	//$portion =
	$range = $pm->get_range();
	$nums = $pm->show() ;

	//debug($range);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Manage Movies</TITLE>
<link rel="stylesheet" type="text/css" href="admin.css">
<script language="Javascript">
<!--
function put_image(aField) {
	var imgSrc = showModalDialog('img_library.php?r='+Math.random(), '',
      'dialogHeight:400px; dialogWidth:520px; resizable:no; status:no');

	aField.focus();
	aField.value = "";
	var SEL = document.selection.createRange() ;
	if(imgSrc!=null && imgSrc!="undefined") {
		SEL.text = imgSrc ;
	}


}
//-->
</script>
</HEAD>
<body bgcolor="#FFFFFF" text="#000000" leftmargin="10" topmargin="20" marginwidth="0" marginheight="0">

<TABLE border=0 cellspacing=0 cellpadding=10 align=center width=620>
<tr>

	<td valign=top>

		 <img src=../images/logo.jpg><BR>
		<h1>Manage Movies</h1><P>


<?php
if(isset($_REQUEST[ef])) {
	$single = mov_get_by_name($_REQUEST[ef]);
	//debug($signle);
	echo '<h2><center>'.$_REQUEST[ef].'</center></h2>'._E;
	echo '<form name="movie" method=post>'._E;
	echo '<input type="hidden" name="actiontype" value="update">'._E;
	echo '<input type="hidden" name="replace_date" value="'.(!empty($single)?0:1).'">'._E;
	echo '<input type="hidden" name="ef" value="'.$_REQUEST[ef].'">'._E;
	echo '<input type="hidden" name="p" value="'.($_REQUEST[p]?$_REQUEST[p]:1).'">'._E;
	echo '<table align="center" width=100% border=1 cellspacing=2 cellpadding=2>'._E ;
		echo '<tr>'._E ;
			echo '<td width=30%>'._E ;
				echo 'Movie Title' ;
			echo '</td>'._E ;
			echo '<td>'._E ;
				echo '<input type="text" name="m_name" style="width: 100%" value="'.htmlspecialchars($single[1]).'">'._E ;
			echo '</td>'._E ;
		echo '</tr>'._E ;
		echo '<tr>'._E ;
			echo '<td width=30%>'._E ;
				echo 'Thumbnail <img src="../system/tb_imgfolder.gif" border="0" width="16" height="16" align="abstop" style="cursor: hand;" onclick="put_image(document.forms.movie.m_thumb)">' ;
			echo '</td>'._E ;
			echo '<td>'._E ;
				echo '<input type="text" name="m_thumb" style="width: 100%" value="'.htmlspecialchars($single[2]).'">'._E ;
			echo '</td>'._E ;
		echo '</tr>'._E ;
		echo '<tr>'._E ;
			echo '<td width=30%>'._E ;
				echo 'Player var' ;
			echo '</td>'._E ;
			echo '<td>'._E ;
				echo '<input type="text" name="m_var" style="width: 100%" value="'.htmlspecialchars($single[3]).'">'._E ;
			echo '</td>'._E ;
		echo '</tr>'._E ;
		echo '<tr>'._E ;
			echo '<td width=30%>'._E ;
				echo 'Movie text' ;
			echo '</td>'._E ;
			echo '<td>'._E ;
				echo '<textarea name="m_txt" rows="4" style="width: 100%; font-family: Arial, Tahoma, Verdana;">'.htmlspecialchars($single[6]).'</textarea>'._E ;
			echo '</td>'._E ;
		echo '</tr>'._E ;
		echo '<tr>'._E ;
			echo '<td colspan=2 align=center>'._E ;
				echo '<input type="submit" name=set value="save">' ;
			echo '</td>'._E ;
		echo '</tr>'._E ;
	echo '</table>'._E ;
} // i f
		echo '<p>'. $nums .'</p>';
?>
		<table align="center" width=100% border=0 cellspacing=2 cellpadding=2>
<?php
	for($i=0; $i<count($range); $i++) {
		$item = mov_get_by_name($allfiles[$range[$i]]);
		//print_r($item);
		echo tr($i)._E ;
			echo '<td width=16>'._E ;
				echo '<a href="?p='.($_REQUEST[p]?$_REQUEST[p]:1).'&ef='.$allfiles[$range[$i]].'" title="Edit description"><img src="../system/tb_edit.gif" border="0" width="16" height="16"></a>' ;
			echo '</td>'._E ;
			echo '<td width=16>'._E ;
				echo '<a href="?p=1&d='.$allfiles[$range[$i]].'" title="Delete description from db and file from \'movies\' folder" onclick="return confirm(\'Delete description from db and file from \\\'movies\\\' folder?\')"><img src="../system/tb_delete.gif" border="0" width="16" height="16"></a>' ;
			echo '</td>'._E ;
			echo '<td>'._E ;
				echo '<b>'. $allfiles[$range[$i]] . '</b>' ;
			echo '</td>'._E ;
			echo '<td width=16>'._E ;
				echo '<img src="../system/tb_'.(!empty($item)?'active':'inactive').'.gif" border="0" width="16" height="16">' ;
			echo '</td>'._E ;
		echo '</tr>'._E ;
		if(!empty($item)) {
			echo '<tr>'._E ;
				echo '<td colspan=4 align=right style="font-style: italic; font-size: xx-small;">'._E ;
					echo $item[1]?$item[1]:'&nbsp;' ;
				echo '</td>'._E ;
			echo '</tr>'._E ;
		} // i f
	} // f o r
?>
		</table>
		<p>
		<?=$nums?>       &nbsp;&nbsp;&nbsp;(Do not delete file called ad.flv) <a href=help.php target=new>Need Help ?</a>
		<P>View Public Files <a href=/premiumvideo target=_blank>Click Here  </a>
		<BR><BR>
	</td>
</tr>
<tr>
	<td colspan=2 align=center>
<BR>
<BR>
<BR>
<BR>
<a href="http://affiliates.macromedia.com/b.asp?id=2097&p=go/dr_home_aff1" target="_blank"><IMG SRC="../system/mwm_flmx_88_31.gif" WIDTH="88" HEIGHT="31" BORDER="0" ALT="Powered By Flash MX"></A>&nbsp;&nbsp;<A HREF="http://www.php.net" target="_blank"><IMG SRC="../system/powered_by_php.jpg" WIDTH="88" HEIGHT="31" BORDER="0" ALT="Powered By PHP"></A>&nbsp;&nbsp;<A HREF="http://www.macromedia.com/go/getflashplayer/" target="_blank"><IMG SRC="../system/alternate.gif" WIDTH="88" HEIGHT="31" BORDER="0" ALT="Get the latest Free Flash Player"></A>
	</td>
</tr>
</table>

</BODY>
</HTML>
